package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api("管理端订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //订单搜索
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索条件:{}",ordersPageQueryDTO);
        PageResult result = orderService.condditionSearch(ordersPageQueryDTO);
        return Result.success(result);
    }

    //商家查看订单详情
    @GetMapping("/details/{id}")
    @ApiOperation("查看订单详情")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("商家要查看的订单id:{}",id);
        OrderVO orderVO = orderService.orderDetails(id);
        return Result.success(orderVO);
    }
    //商家接单
    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("商家接单的id:{}",ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }
    //商家拒单
    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("商家拒单:{}",ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    //商家取消订单
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto) {
        log.info("商家取消的订单id：{}",dto.getId());
        orderService.adminCancelOrder(dto);
        return Result.success();
    }
    //商家派送订单
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliveryOrder(@PathVariable Long id){
        log.info("要派送的订单id:{}",id);
        orderService.deliveryOrder(id);
        return Result.success();
    }
    //商家完成订单
    @PutMapping("/complete/{id}")
    @ApiOperation("商家完成订单")
    public Result completeOrder(@PathVariable Long id){
        log.info("商家完成的订单id:{}",id);
        orderService.completeOrder(id);
        return Result.success();
    }
    //统计各状态订单数量
    @GetMapping("/statistics")
    @ApiOperation("统计各状态订单数量")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO vo = orderService.statisticsOrder();
        return Result.success(vo);
    }
}
